import { defineStore } from "pinia";
// 引入数据类型
import type { categoryStoreStateType } from './interface/category';
// 引入请求
import { reqC1List, reqC2List, reqC3List } from "@/api/product/attr/attr";
export const useCategoryStore = defineStore("category", {
  state: ():categoryStoreStateType => ({
    c1List: [],
    c1id: "",
    c2List: [],
    c2id: "",
    c3List: [],
    c3id: "",
  }),
  actions: {
    // 获取一级分类数据
    async getC1List() {
      let result = await reqC1List();
      this.c1List = result;
    },
     //一级分类下拉菜单触发change事件， 获取二级分类数据
    async getC2List() {
    //    一级分类菜单发生改变,下两级数据清空
    this.c2List=[]
    this.c2id= ""
    this.c3List=[]
    this.c3id=""
      let result = await reqC2List(this.c1id);
      this.c2List = result;
    },
    //二级分类下拉菜单触发change事件， 获取三级分类数据
    async getC3List() {
        this.c3List=[]
        this.c3id=""
      let result = await reqC3List(this.c2id);
      this.c3List = result;
    },
  },
});
